package com.ruoyi.system.mapper;

import com.ruoyi.system.domain.SysGameRecord;
import com.ruoyi.system.domain.member_info;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author kaka.huang
 * @for study
 */

/*
 * 竞赛成绩表接口
 * */
@Mapper
public interface SysCompetitionMapper {
/*
  要求：
  显示字段包括：
  时间、名称、结果、top、成员
  其中成员用、连接，根据game_id联查
  **/

    //    列表展示
    @Select("<script>" +
            "SELECT game_record.game_id, game_record.game_time, game_record.game_name, game_record.game_result, game_record.top, game_record.certificate, member_info.name " +
            "FROM game_record " +
            "LEFT JOIN game_member_mapping ON game_record.game_id = game_member_mapping.game_id " +
            "LEFT JOIN member_info ON game_member_mapping.member_id = member_info.member_id " +
            "<where>" +
            "<if test='postCode != null and postCode != \"\"'>" +
            "AND game_record.game_time LIKE CONCAT('%', #{postCode}, '%')" +
            "</if>" +
            "<if test='postName != null and postName != \"\"'>" +
            "AND game_record.game_name LIKE CONCAT('%', #{postName}, '%')" +
            "</if>" +
            "<if test='status != null and status != \"\"'>" +
            "AND game_record.game_result LIKE CONCAT('%', #{status}, '%')" +
            "</if>" +
            "</where>" +
            "</script>")
    List<SysGameRecord> selectCompetitionMapper(@Param("postCode") String postCode, @Param("postName") String postName, @Param("status") String status);

    //查询所有奖项种类
    @Select("select distinct game_result from game_record")
    List<String> selectAllResultKind();

    //    查询组员
    @Select("select member_id,name from member_info where name LIKE CONCAT('%',#{searchName}, '%')")
    List<member_info> selectMemberInfo(String searchName);

    //    新增game_record
    @Insert("INSERT INTO game_record (game_id, game_name, game_time, game_result, top) " +
            "VALUES (#{game_id}, #{game_name}, #{game_time}, #{game_result}, #{top})")
    int insertGameRecord(@Param("game_id") String game_id,
                         @Param("game_name") String game_name,
                         @Param("game_time") String game_time,
                         @Param("game_result") String game_result,
                         @Param("top") Integer top);


    //  新增mapping映射表
    @Insert("insert into game_member_mapping (game_meb_mapping_id, game_id, member_id) values (#{game_meb_mapping_id}, #{game_id}, #{member_id})")
    int insertGameMebMapping(@Param("game_meb_mapping_id") String game_meb_mapping_id,
                             @Param("game_id") String game_id,
                             @Param("member_id") String member_id);

    //    上传图片
    @Update("update game_record set certificate = #{certificate} where game_id = #{game_id}")
    int updateCertificate(@Param("certificate") String certificate, @Param("game_id") String game_id);

    //    修改数据
    @Update("update game_record set game_name = #{game_name}, game_time = #{game_time}, game_result = #{game_result}, top = #{top} where game_id = #{game_id}")
    int UpdateGameRecord(@Param("game_id") String game_id, @Param("game_name") String game_name, @Param("game_time") String game_time, @Param("game_result") String game_result, @Param("top") Integer top);

    //    修改mapping表
    @Update("update game_member_mapping set member_id = #{member_id} where game_id = #{game_id}")
    int UpdateGameMebMapping(@Param("member_id") String member_id, @Param("game_id") String game_id);

    //    删除mapping表
    @Delete("delete from game_member_mapping where game_id = #{game_id}")
    int DeleteMapping(@Param("game_id") String game_id);

    //    删除game_record表
    @Delete("delete from game_record where game_id = #{game_id}")
    int DeleteGameRecord(@Param("game_id") String game_id);
}
